package com.newasia.server.controller.form;

import com.newasia.server.common.exception.ValidateException;
import com.newasia.server.common.result.ManagementRetCode;
import com.newasia.server.dal.entitys.User;
import com.newasia.server.shiro.EncryptionUtil;
import com.newasia.server.shiro.ShiroUtils;
import jodd.util.StringUtil;
import lombok.Data;

/**
 * @author LiChong
 * @description 变更密码表单
 * @date 2020/4/8
 */
@Data
public class ChangePassForm implements Form {

    private String oldPassword;
    private String newPassword;
    private String repeatPassword;

    @Override
    public void requestCheck() {
        String password = EncryptionUtil.md5(oldPassword);
        if (!StringUtil.equals(password,ShiroUtils.getUserInfo().getPass())){
            throw new ValidateException(
                    ManagementRetCode.PASSWORD_ERROR.getCode(),
                    ManagementRetCode.PASSWORD_ERROR.getMessage());
        }
        if (!StringUtil.equals(newPassword,repeatPassword)){
            throw new ValidateException(
                    ManagementRetCode.PASSWORD_INCONFORMITY.getCode(),
                    ManagementRetCode.PASSWORD_INCONFORMITY.getMessage());
        }
    }
}
